package com.zhiwei.jenkins.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

public class GenerateIdUtil {

    private static final String zk_project_prefix = "PJ";

    /**
     * 最大的随机码
     */
    private static final Integer maxRamdonKey = 999999;

    /**
     * 最大数字位数
     */
    private static final Integer MaxDigit = 4;

    /**
     * 生成项目编码
     * @param projectPrefix 6位行政区码
     * @return
     */
    /*public static final String projectCode(String projectPrefix) {
        return generateIdByTime(projectPrefix, zk_project_prefix);
    }*/

    /**
     * 根据日期生成业务编号
     * 前缀+yyyyMMdd+4位随机数
     *
     * @param prefixStr ： 业务编码
     * @return
     */
   /* public static final String generateIdByTime(String prefixStr, String zkPrefix) {
        String generatedId;
        Date currentDate = new Date();
        //获取当前时间戳
        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
        String idStr = sf.format(currentDate);
        // 获取四位随机数
        Integer projectCodeSuffix = CuratorHelper.getCount(currentDate, zkPrefix);
        if (null == projectCodeSuffix)
            throw new RuntimeException("获取分布式计数器失败");
        if (maxRamdonKey < projectCodeSuffix) {
            logger.warn("项目编码超出当日最大限制，{}", projectCodeSuffix);
            throw new RuntimeException("项目编码超出当日最大限制");
        }
        String projectCodeSuffixStr = NumberUtils.formatDigit(projectCodeSuffix, MaxDigit, MaxDigit, false);
        generatedId = prefixStr + idStr + projectCodeSuffixStr;
        return generatedId;
    }*/
}
